<?php
namespace App\Service\OrderService\OrderRouteService;

use App\Service\Code\Normal;
use App\Model\PssModel\OrderSupplier;
use Service\AppService\IdService;
use App\Service\OrderService\BaseSupplierRouterService;
use App\Service\VendorClient\Shopjianrunji\ShopjianrunjiApiClient;
use App\Service\TraitService\SupplierRouterOrderTrait;
use App\Model\CommodityModel\SupplierCommodity;

/**
 * 建闰极上游对接
 * @author: hj
 */
class Shopjianrunji extends BaseSupplierRouterService {

    use SupplierRouterOrderTrait;

    /**
     * 订单支付
     * @param array $param
     * @return array
     */
    public function orderPay($param = []) {
        $goodsList      = $param['orderGoods'];
        $supplierSkuIds = array_column($goodsList, 'supplier_skuid');
        $goodsIdArr     = SupplierCommodity::whereIn('ID', $supplierSkuIds)->pluck('SupplierCommodityKey', 'ID')->toArray();
        foreach ($param['orderGoods'] as &$item) {
            if (isset($goodsIdArr[$item['supplier_skuid']])) {
                $item['supplier_commodity_key'] = $goodsIdArr[$item['supplier_skuid']];
            }
            unset($item);
        }
        return $this->callSdkApi(ShopjianrunjiApiClient::class, $param['apiBody'])->createOrder($param);
    }

    /**
     * 订单取消
     * @param array $param
     * @return array
     */
    public function orderCancel($param = []) {
        return Normal::returnCode(Normal::SUC, "处理完成");
    }

    /**
     * 订单售后
     * @param array $param
     * @return array
     */
    public function orderAfterSale($param = []) {
        return $this->callSdkApi(ShopjianrunjiApiClient::class, $param['apiBody'])->cancelOrder($param);
    }

    /**
     * 商品列表查询接口
     * @param array $param
     * @return array
     */
    public function queryGoodsList($param = []) {
        return Normal::returnCode(Normal::SUC, "商品需人工自建导入");
    }

    /**
     * 获取物流信息
     * @param array $param
     */
    public function queryOrderExpress($param = []) {
        return Normal::returnCode(Normal::SUC, "此供应商物流信息会主动推送");
    }
}